//
//  ToastManager.m
//  gdemm
//
//  Created by yongwu on 15/12/4.
//  Copyright © 2015年 goldensoft. All rights reserved.
//

#import "ToastManager.h"
#import "Utils.h"
@implementation ToastManager
MBProgressHUD *hub;

+(void)showToastWithLable:(UIView *)rootView :(NSString *)toast{
    hub = [MBProgressHUD showHUDAddedTo:rootView animated:YES];
    hub.labelText = toast;

    hub.mode = MBProgressHUDModeText;
    hub.margin = 10.f;
    hub.removeFromSuperViewOnHide = YES;

    [hub show:YES];
    [hub hide:YES afterDelay:1];
}
+(void)showToastWindowWithLable:(UIWindow *)window :(NSString *)toast{
    hub = [MBProgressHUD showHUDAddedTo:window animated:YES];
    hub.labelText = toast;
    
    hub.mode = MBProgressHUDModeText;
    hub.margin = 10.f;
    hub.removeFromSuperViewOnHide = YES;
    
    [hub show:YES];
    [hub hide:YES afterDelay:2];
}

+(void)showColorToast:(UIView *)rootView WithLable:(NSString *)strToast{
    hub = [[MBProgressHUD alloc]initWithView:rootView];
    [rootView addSubview:hub];
    hub.labelText = strToast;
    hub.mode = MBProgressHUDModeText;
    hub.color = [Utils UIColorFromHex:GDBLUE];
    hub.margin = 10.f;
    hub.removeFromSuperViewOnHide= YES;
    [hub show:YES];
    [hub hide:YES afterDelay:2];
}

+(void)showFailed:(UIView *)rootView withErrorInfo:(NSString *)msg{
    hub = [[MBProgressHUD alloc]initWithView:rootView];
    [rootView addSubview:hub];
    if (msg == nil) {
        hub.labelText = NSLocalizedString(@"str_failed", @"");
    }else{
        hub.labelText = msg;
    }
    hub.mode = MBProgressHUDModeCustomView;
    hub.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"error"]];
    hub.square = YES;
    hub.margin = 10.f;
    hub.removeFromSuperViewOnHide= YES;
    [hub show:YES];
    [hub hide:YES afterDelay:2];
}

+(void)showSuccess:(UIView *)rootView{
    hub = [[MBProgressHUD alloc]initWithView:rootView];
    [rootView addSubview:hub];
    hub.labelText = NSLocalizedString(@"", @"");
    hub.mode = MBProgressHUDModeCustomView;
    hub.customView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Checkmark"]];
    
    hub.margin = 10.f;
    hub.removeFromSuperViewOnHide= YES;
    [hub show:YES];
    [hub hide:YES afterDelay:2];
}
@end
